﻿RS.Global = (function() {
    var self = this;
    var global = null;

    var translateKey = function(key) {
        if (!key)
            return '';

        if (!global)
            global = new Globalize(app.User.Settings.Language);

        return global.localize(key) || key;
    };

    var getCultureDefinition = function() {
        return Globalize.cultures[saasPlatform.Settings.CurrentCulture];
    };

    var formatInternal = function(value, format, cultureSelector) {
        if (!global)
            global = new Globalize(saasPlatform.Settings.CurrentCulture);

        return global.format(value, format, cultureSelector);
    };

    return {
        translate: function(key) { return translateKey(key); },
        getCultureDefinition: function() { return getCultureDefinition(); },
        getCalendarPatterns: function() { return getCultureDefinition().calendars.standard.patterns; },
        getMonths: function(abbreviated) {
            var months = getCultureDefinition().calendars.standard.months;
            return abbreviated ? months.namesAbbr : months.names;
        },
        getDays: function(abbreviated) {
            var days = getCultureDefinition().calendars.standard.days;
            return abbreviated ? days.namesShort : days.names;
        },
        format: function (value, format, cultureSelector) { return formatInternal(value, format, cultureSelector); }
    };
})();